package com.hand.cloud.controller;

import com.hand.cloud.dto.StudentVo;
import com.hand.cloud.entity.Student;
import com.hand.cloud.result.Result;
import com.hand.cloud.service.EducFeignService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/feign/educ")
public class EducController {
    @Resource
    private EducFeignService educFeignService;

    @PostMapping("/student/add")
    public Result<Student> insertStudent(@RequestBody Student student) {
        return educFeignService.insertStudent(student);
    }

    @GetMapping("/student/{id}")
    public Result<Student> getStudent(@PathVariable("id") Long id) {
        return educFeignService.getStudent(id);
    }

    @GetMapping("/search/{name}")
    public Result<List<Student>> searchStudent(@PathVariable(value = "name", required = false) String name) {
        return educFeignService.searchStudent(name);
    }

    @GetMapping("/search")
    public Result<List<Student>> searchStudent() {
        return educFeignService.searchStudent();
    }

    @GetMapping("/student/all")
    public Result<List<Student>> studentAll() {
        return educFeignService.studentAll();
    }

    @DeleteMapping("/delete/{id}")
    public Result<Integer> deleteStudent(@PathVariable("id") Long id) {
        return educFeignService.deleteStudent(id);
    }

    @PutMapping("/update")
    public Result<Student> updateStudent(@RequestBody Student student) {
        return educFeignService.updateStudent(student);
    }

    @GetMapping("/score-table/{id}")
    public Result<StudentVo> getScoreTable(@PathVariable(value = "id") Long id) {
        return educFeignService.getScoreTable(id);
    }

    @GetMapping("/score-table/all")
    public Result<List<StudentVo>> getScoreTableAll() {
        return educFeignService.getScoreTableAll();
    }

    @PostMapping("/student/add-score")
    public Result<StudentVo> addScore(@RequestBody Map<String, Number> scoreMap) {
        return educFeignService.addScore(scoreMap);
    }

    @PostMapping("/student/add-score-beach")
    public Result<List<StudentVo>> addScoreBeach(@RequestBody List<Map<String, Object>> scores) {
        return educFeignService.addScoreBeach(scores);
    }

}
